package com.shelpe.services.lexicon.utils;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;

import com.shelpe.services.lexicon.entity.KeywordMetric;
import com.shelpe.services.lexicon.entity.KeywordRecommend;
import com.shelpe.services.lexicon.entity.WordInsightMetric;
import com.shelpe.services.lexicon.entity.metrics.InsightMetrics;

public abstract class MetricUtils {

	public static KeywordMetric find(List<KeywordMetric> metrics, final KeywordRecommend recommend){
		return (KeywordMetric) CollectionUtils.find(metrics, new Predicate(){

			@Override
			public boolean evaluate(Object object) {
				KeywordMetric metric = (KeywordMetric) object;
				return recommend.getWord().equals(metric.getWord());
			}
			
		});
	}
	
	public static InsightMetrics findWordInsightMetric(List<WordInsightMetric> metrics, final KeywordRecommend recommend){
		InsightMetrics found = null;
		for(WordInsightMetric metric: metrics){
			if(recommend.getWord().equals(metric.getWord()) && metric.getMetric() != null){
				if(found != null){
					found = found.add(metric.getMetric());
				}else{
					found = metric.getMetric();
				}
			}
		}
		
		return found;
	}
}
